//
//  M_JifenCell.swift
//  letuofu
//
//  Created by WH-JS on 2020/1/10.
//  Copyright © 2020 WH-JS. All rights reserved.
//

import UIKit

class M_JifenCell: QuickTableCellWithInit<[String : Any?]> {
    let titleLab = UILabel()
    let timeLab = UILabel()
    let priceLab = UILabel()

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    
    override class func heightOf(_ data:[String:Any?])->CGFloat{
        return 71
    }
    
    override func initCell(container: UIView) {
        container.backgroundColor = .white
        
        drawLabel(label: titleLab, text: titleLab.text, fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.top.equalToSuperview().offset(20)
            make.left.equalToSuperview().offset(10)
        }
        
        drawLabel(label: timeLab, text: timeLab.text, fontSize: 12, fontWeight: .regular, textColor: .x999999) { (make) in
            make.top.equalTo(titleLab.snp.bottom).offset(10)
            make.left.equalToSuperview().offset(10)
        }
        
        drawLabel(label: priceLab, text: priceLab.text, fontSize: 18, fontWeight: .regular, textColor: .x999999) { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
        
        //画横线
        let line = drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
    }
    
    override func fillCell(_ data: [String:Any?], at index: Int) {
        let stime = data.getString("relationName")?.replacingOccurrences(of: "-", with: ".")
        let etime = data.getString("tradeTime")?.replacingOccurrences(of: "-", with: ".")
        titleLab.text = String(stime ?? "未知项目")
        timeLab.text = String(etime ?? "现在")
        if let price = anyToString(data["cents"] as Any?),let flowTypeCode = data.getString("flowTypeCode") {
            switch flowTypeCode {
            case "108001":
                priceLab.text = "+" + price
                priceLab.textColor = .xFC4C02
            case "108002":
                priceLab.text = "-" + price
                priceLab.textColor = .x999999
            default:
                priceLab.text = "+" + price
                priceLab.textColor = .xFC4C02
            }
        }
    }
}
